program main
    implicit none
    integer,external :: S
    write(*,*) "S1=",S(1,100,0)
    write(*,*) "S2=",S(10,100,5)
end program

integer function S(m,n,k)
    integer :: m,n,k,i
    integer :: t(m:n)
    t=(/ (i-k,i=m,n) /)
    S=sum(t**2)
end function
